package com.net.wanjian.networkhospitalmanager.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.bean.NotificationTypeLocalBean;

import java.util.List;

/**
 * Description:
 * Created by lidongcai on 17/7/4.
 * Email:  lidongcaiocc@163.com
 */

public class NotificationTypeAdapter extends BaseAdapter {
    private Context mContext;
    private List<NotificationTypeLocalBean> typeList;
    private int currentSelectPosition;

    public NotificationTypeAdapter(Context mContext, List<NotificationTypeLocalBean> typeList) {
        this.mContext = mContext;
        this.typeList = typeList;
    }

    @Override
    public int getCount() {
        return typeList == null ? 0 : typeList.size();
    }

    @Override
    public Object getItem(int position) {
        return typeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_notification_type, parent,false);
            holder.nameTV = (TextView) convertView.findViewById(R.id.item_teacher_event_listview_right_tv);

            holder.tagImageView = (ImageView) convertView.findViewById(R.id.item_teacher_event_listview_right_select_iv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.nameTV.setText(typeList.get(position).getTypeName());
        if (position == currentSelectPosition) {
            holder.nameTV.setTextColor(mContext.getResources().getColor(R.color.colorMain));
            holder.tagImageView.setVisibility(View.VISIBLE);
        } else {
            holder.nameTV.setTextColor(Color.BLACK);
            holder.tagImageView.setVisibility(View.GONE);
        }

        return convertView;
    }

    public int getCurrentSelectPosition() {
        return currentSelectPosition;
    }

    public void setCurrentSelectPosition(int currentSelectPosition) {
        this.currentSelectPosition = currentSelectPosition;
    }

    static class ViewHolder {
        TextView nameTV;
        ImageView tagImageView;
    }
}
